﻿using System.Web;
using System.Collections;
using System;
using System.Configuration;

/// <summary>
///BaseWeb 的摘要说明
/// </summary>
public class BaseWeb
{
  
    public static readonly BaseWeb instance = new BaseWeb();
    #region 清除所有缓存
    /// <summary>
    /// 清除所有缓存
    /// </summary>
    public void RemoveAllCache()
    {

        System.Web.Caching.Cache cache = HttpRuntime.Cache;
        IDictionaryEnumerator CacheEnum = cache.GetEnumerator();
        ArrayList al = new ArrayList();
        while (CacheEnum.MoveNext())
        {
            al.Add(CacheEnum.Key);
        }

        foreach (string key in al)
        {
            cache.Remove(key);
        }
    }
    #endregion

    public static string BaseUrl
    {
        get
        {
            if (System.Web.HttpContext.Current.Request.Url.Port == 80)
            {
                return "http://" + System.Web.HttpContext.Current.Request.Url.Host;
            }
            else
            {
                return "http://" + System.Web.HttpContext.Current.Request.Url.Host + ":" + System.Web.HttpContext.Current.Request.Url.Port;
            }
        }
    }


    #region 用户登录后的userid
    public int UserId
    {
        get
        {
            try
            {
                return Convert.ToInt32(System.Web.HttpContext.Current.Session["UserId"]);
            }
            catch
            {
                return 0;
            }
        }
        set
        {
            System.Web.HttpContext.Current.Session["UserId"] = value;
        }
    }
    #endregion

    #region 后台登录后的AdminID
    public int AdminId
    {
        get
        {
            try
            {
                return Convert.ToInt32(System.Web.HttpContext.Current.Session["AdminId"]);
            }
            catch
            {
                return 0;
            }
        }
        set
        {
            System.Web.HttpContext.Current.Session["AdminId"] = value;
        }
    }
    #endregion

    public static bool IsAccessData
    {
        get
        {
            string dal = ConfigurationManager.AppSettings["DAL"];
            if (dal.ToLower() == "SQLServerDAL".ToLower())//sqlserver数据库
            {
                return false;
            }
            return true;
        }
    }

}
